package jian.thread.newbie;

public class TestSynchronized {

	public static void main(String[] args) {

		final Outputer printer = new Outputer();
		Thread t1 = new Thread(new Runnable() {

			@Override
			public void run() {
				printer.print("tracytracy");
			}
		});

		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				printer.print("jianjian");
			}
		});

		Thread t3 = new Thread(new Runnable() {
			@Override
			public void run() {
				printer.print("longlong");
			}
		});

		t1.start();
		t2.start();
		t3.start();
	}

}

class Outputer {

	public void print(String value) {
		for (int i = 0; i < value.length(); i++) {
			System.out.print(value.charAt(i));
		}
	}

	public synchronized void printSync(String value) {
		for (int i = 0; i < value.length(); i++) {
			System.out.print(value.charAt(i));
		}
	}

	public void printLock(String value) {
		synchronized (this) {
			for (int i = 0; i < value.length(); i++) {
				System.out.print(value.charAt(i));
			}
		}
	}
}
